var http = require('http');
var url = require('url');
var router = require('./router');

http.createServer(function(request,response){
	//response.writeHead(200,{'Content-Type':'text/html;charset=utf8'});
	//response.writeHead(200,{'Content-Type':'image/jpeg'});
	if(request.url !== '/favicon.ico'){
		pathname = url.parse(request.url).pathname;
		pathname = pathname.replace(/\//,'');
		try{
			router[pathname](request,response);
		}catch(err){
			console.log('出错' + err);
			response.writeHead(200,{'Content-Type':'text/html;charset=uft-8'});
			response.write(err);		
		};
		console.log('Server执行完毕');
		//读取图片
		//optfile.readImg('./imgs/pig.png',response)
	}	
}).listen(8000);
console.log('Server is running at http://127.0.0.1:8000/');